package 笔试;

import java.awt.*;

public class 四边形面积 {

    public long getArea (Point p1, Point p2, Point p3, Point p4) {
        double area1 = calTri(p1, p2, p3);
        double area2 = calTri(p1, p3, p4);
        return (long) (area1 + area2 + 0.5);
    }

    private double calTri(Point p1, Point p2, Point p3) {
        double a = calLen(p1, p2);
        double b = calLen(p1, p3);
        double c = calLen(p2, p3);
        double p = (a + b + c) / 2;
        return Math.sqrt(p * (p - a) * (p - b) * (p - c));
    }

    private double calLen(Point p1, Point p2) {
        int x = p1.x - p2.x;
        int y = p1.y - p2.y;
        return Math.sqrt(x * x + y * y);
    }
}
